﻿package mortal.game.view.guide
{
    import com.gengine.resource.*;
    import com.gengine.resource.info.*;
    import flash.display.*;
    import flash.geom.*;
    import mortal.game.mvc.*;
    import mortal.game.scene3D.display3d.icon3d.*;
    import mortal.game.scene3D.map3D.*;
    import mortal.game.scene3D.player.item.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.mainUI.Navbar.*;

    public class GuidePickupItemFly extends Object
    {
        private var _maxNum:int = 10;
        private var _arr:Array;
        private var _players:Array;
        private var _places:Array;
        public static var instance:GuidePickupItemFly = new GuidePickupItemFly;

        public function GuidePickupItemFly()
        {
            this._arr = [];
            this._players = [];
            this._places = [];
            return;
        }// end function

        public function checkAndFlyToBackpack(param1:int, param2:String = "pack") : Boolean
        {
            var player:ItemPlayer;
            var sp:Point;
            var onLoaded:Function;
            var code:* = param1;
            var moduleType:* = param2;
            onLoaded = function (param1:ImageInfo) : void
            {
                var _loc_2:* = Icon3DRender.imgW / Icon3DRender.gridNum;
                if (player.xnum <= 0 || player.ynum <= 0)
                {
                    return;
                }
                var _loc_3:* = new BitmapData(_loc_2 * player.xnum, _loc_2 * player.ynum, true, 16777215);
                _loc_3.draw(param1.bitmapData, new Matrix(1, 0, 0, 1, (-_loc_2) * player.offsetX, (-_loc_2) * player.offsetY));
                var _loc_4:* = (GameController.navbar.view as NavbarModule).getNavbarIconGlobalPoint(moduleType);
                var _loc_5:* = _loc_2 * player.xnum;
                var _loc_6:* = _loc_2 * player.ynum;
                var _loc_7:* = 35 / Math.max(_loc_5, _loc_6);
                if (_loc_5 <= 40 && _loc_6 <= 40)
                {
                    _loc_7 = 1;
                }
                sp.x = sp.x - SceneRange.display.x;
                sp.y = sp.y - SceneRange.display.y;
                sp.y = sp.y + 15;
                FlyToNavbarTool.flyToAnyPoint(_loc_3, sp, _loc_4, null, 32 * player.xnum, 32 * player.ynum, true, _loc_7, _loc_7);
                return;
            }// end function
            ;
            var index:* = this._arr.indexOf(code);
            if (index < 0)
            {
                return false;
            }
            player = this._players[index];
            sp = this._places[index];
            if (player == null)
            {
                return false;
            }
            this._arr.splice(index, 1);
            this._players.splice(index, 1);
            this._places.splice(index, 1);
            LoaderManager.instance.load(player.dropIcon, onLoaded);
            return true;
        }// end function

        public function inCode(param1:int, param2:ItemPlayer) : void
        {
            var _loc_3:* = this._arr.unshift(param1);
            this._players.unshift(param2);
            this._places.unshift(new Point(param2.x2d, param2.y2d));
            if (_loc_3 > this._maxNum)
            {
                this._arr.pop();
                this._players.pop();
                this._places.pop();
            }
            return;
        }// end function

    }
}
